home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / dev / gcc / objam01.lha / objam / objc / Protocol.m < prev    next >
Encoding:
Text File  |  1994-12-11  |  2.3 KB  |  109 lines

  1. /*
  2. ** ObjectiveAmiga: Implementation of class Protocol
  3. ** See GNU:lib/libobjam/ReadMe for details
  4. */
  5.  
  6.  
  7. #include <objc/Protocol.h>
  8. #include <objc/objc-api.h>
  9.  
  10. /* Method description list */
  11. struct objc_method_description_list {
  12.         int count;
  13.         struct objc_method_description list[1];
  14. };
  15.  
  16.  
  17. @implementation Protocol
  18. {
  19. @private
  20.         char *protocol_name;
  21.         struct objc_protocol_list *protocol_list;
  22.         struct objc_method_description_list *instance_methods, *class_methods; 
  23. }
  24.  
  25. /* Obtaining attributes intrinsic to the protocol */
  26.  
  27. - (const char *)name
  28. {
  29.   return protocol_name;
  30. }
  31.  
  32. /* Testing protocol conformance */
  33.  
  34. - (BOOL) conformsTo: (Protocol *)aProtocolObject
  35. {
  36.   int i;
  37.   struct objc_protocol_list* proto_list;
  38.  
  39.   if (!strcmp(aProtocolObject->protocol_name, self->protocol_name))
  40.     return YES;
  41.  
  42.   for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
  43.     {
  44.       for (i=0; i < proto_list->count; i++)
  45.     {
  46.       if ([proto_list->list[i] conformsTo: aProtocolObject])
  47.         return YES;
  48.     }
  49.     }
  50.  
  51.   return NO;
  52. }
  53.  
  54. /* Looking up information specific to a protocol */
  55.  
  56. - (struct objc_method_description *) descriptionForInstanceMethod:(SEL)aSel
  57. {
  58.   int i;
  59.   struct objc_protocol_list* proto_list;
  60.   const char* name = sel_get_name (aSel);
  61.   struct objc_method_description *result;
  62.  
  63.   for (i = 0; i < instance_methods->count; i++)
  64.     {
  65.       if (!strcmp ((char*)instance_methods->list[i].name, name))
  66.     return &(instance_methods->list[i]);
  67.     }
  68.  
  69.   for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
  70.     {
  71.       for (i=0; i < proto_list->count; i++)
  72.     {
  73.       if ((result = [proto_list->list[i]
  74.              descriptionForInstanceMethod: aSel]))
  75.         return result;
  76.     }
  77.     }
  78.  
  79.   return NULL;
  80. }
  81.  
  82. - (struct objc_method_description *) descriptionForClassMethod:(SEL)aSel;
  83. {
  84.   int i;
  85.   struct objc_protocol_list* proto_list;
  86.   const char* name = sel_get_name (aSel);
  87.   struct objc_method_description *result;
  88.  
  89.   for (i = 0; i < class_methods->count; i++)
  90.     {
  91.       if (!strcmp ((char*)class_methods->list[i].name, name))
  92.     return &(class_methods->list[i]);
  93.     }
  94.  
  95.   for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
  96.     {
  97.       for (i=0; i < proto_list->count; i++)
  98.     {
  99.       if ((result = [proto_list->list[i]
  100.              descriptionForClassMethod: aSel]))
  101.         return result;
  102.     }
  103.     }
  104.  
  105.   return NULL;
  106. }
  107.  
  108. @end
  109.